package com.windowes.weichang.service;

import com.windowes.weichang.common.ServerResponse;
import com.windowes.weichang.dao.SplashMapper;
import com.windowes.weichang.pojo.Splash;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/***
 *
 * @author: yangqing
 * @email: qing.yang@bangdao-tech.com
 * @createTime: 2018/5/29 下午11:11
 * @description:
 *
 **/
@Service
public class SplashService {


    @Autowired
    SplashMapper splashMapper;

    /**
     * 获取生效中splash
     *
     * @param limit
     * @return
     */
    public ServerResponse list(Integer limit) {
        List<Splash> splashList = splashMapper.selectEffectList(limit);
        if (splashList == null || splashList.isEmpty()) {
            return ServerResponse.createByErrorMessage("未配置引导信息");
        }
        return ServerResponse.createBySuccess(splashList);
    }

    public ServerResponse insertOrUpdate(Splash splash) {
        if (splash == null || StringUtils.isEmpty(splash.getPicUrl())) {
            return ServerResponse.createByErrorMessage("请补充引导图片参数!");
        }
        if (splash.getId() == null) {
            splashMapper.insertSelective(splash);
        } else {
            splashMapper.updateByPrimaryKeySelective(splash);
        }
        return ServerResponse.createBySuccessMessage("操作成功!");
    }
}
